package com.jkc.xh.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.adapters.core.BaseRecyclerAdapter;
import com.jkc.xh.adapters.viewholder.RefferFriendItemView;
import com.jkc.xh.adapters.viewholder.RefferFriendItemView_;
import com.jkc.xh.models.RefferFriendModel;

/**
 * Created by macintosh on 15/11/17.
 */
public class RefferFriendAdapter extends BaseRecyclerAdapter<RefferFriendModel, View> {
    private final static int TYPE_ITEM = 0;
    private final static int TYPE_HINT = 1;

    @Override
    protected View onCreateItemView(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_ITEM:
                return RefferFriendItemView_.build(parent.getContext());
            case TYPE_HINT:
                TextView view = new TextView(parent.getContext());
                view.setText(R.string.str_invite_hint);
                view.setPadding(20,20,20,20);
                return view;
        }
        return null;
    }

    @Override
    protected void onBindView(View itemView, RefferFriendModel orderModel, int position) {
        switch (getItemViewType(position)) {
            case TYPE_ITEM:
                ((RefferFriendItemView) itemView).bind(orderModel);
                break;
            case TYPE_HINT:
                break;
        }
    }

    @Override
    public int getItemCount() {
        return super.getItemCount() + 1;
    }

    @Override
    public RefferFriendModel get(int location) {
        if (location + 1 == getItemCount()) {
            return null;
        }
        return super.get(location);
    }

    @Override
    public int getItemViewType(int position) {
        if (position + 1 == getItemCount()) {
            return TYPE_HINT;
        } else {
            return TYPE_ITEM;
        }
    }


}
